package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener
{
    private  StringBuffer sb = new StringBuffer();
    private TextView textView;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button)findViewById(R.id.bt12); //指明按钮对象
        textView = findViewById(R.id.tv);
        Button button0 = (Button)findViewById(R.id.bt11);
        Button button1 = (Button)findViewById(R.id.bt1);
        Button button2 = (Button)findViewById(R.id.bt2);
        Button button3 = (Button)findViewById(R.id.bt3);
        Button button4 = (Button)findViewById(R.id.bt4);
        Button button5 = (Button)findViewById(R.id.bt5);
        Button button6 = (Button)findViewById(R.id.bt6);
        Button button7 = (Button)findViewById(R.id.bt7);
        Button button8 = (Button)findViewById(R.id.bt8);
        Button button9 = (Button)findViewById(R.id.bt9);
        Button button10 = (Button)findViewById(R.id.bt10);

        button0.setOnClickListener(this);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
        button4.setOnClickListener(this);
        button5.setOnClickListener(this);
        button6.setOnClickListener(this);
        button7.setOnClickListener(this);
        button8.setOnClickListener(this);
        button9.setOnClickListener(this);
        button10.setOnClickListener(this);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,Main2Activity.class); //通过点击按钮，连接类
                startActivity(intent);
            }
        });
    }
    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.bt1:
            {
                sb.append(1);
                textView.setText(sb.toString());
                break;
            }
            case R.id.bt2:
            {
                sb.append(2);
                textView.setText(sb.toString());
                break;
            }
            case R.id.bt3:
            {
                sb.append(3);
                textView.setText(sb.toString());
                break;
            }
            case R.id.bt4:
            {
                sb.append(4);
                textView.setText(sb.toString());
                break;
            }
            case R.id.bt5:
            {
                sb.append(5);
                textView.setText(sb.toString());
                break;
            }
            case R.id.bt6:
            {
                sb.append(6);
                textView.setText(sb.toString());
                break;
            }
            case R.id.bt7:
            {
                sb.append(7);
                textView.setText(sb.toString());
                break;
            }
            case R.id.bt8:
            {
                sb.append(8);
                textView.setText(sb.toString());
                break;
            }
            case R.id.bt9:
            {
                sb.append(9);
                textView.setText(sb.toString());
                break;
            }
            case R.id.bt10:
            {
                sb.append("*");
                textView.setText(sb.toString());
                break;
            }
            case R.id.bt11:
            {
                sb.append(0);
                textView.setText(sb.toString());
                break;
            }
        }
    }
}

